<%--
  Created by IntelliJ IDEA.
  User: mqy
  Date: 2018/11/7
  Time: 9:19
  To change this template use File | Settings | File Templates.
--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="d" uri="http://dgg.net/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>资质生产数据</title>
    <%@ include file="../../header.jsp" %>
</head>
<body>
<div class="body-main">
    <d:hasUrlAuth authCode="ZZSC_ZS_SYB">
        <form id="scOrderFormCount">
        <ul class="search-business">
            <li>
                事业部：
                <select class="select-style" name="signOrgId" id="signOrgId">
                </select>
            </li>
            <li>
                <button type="button" class="layui-btn layui-btn-mini layui-btn-normal" onclick="refreshSata()">搜索</button>
                <button type="button" class="layui-btn layui-btn-mini layui-btn-normal" onclick="exportOrderCount()">导出</button>
            </li>
        </ul>
        </form>
    </d:hasUrlAuth>
    <div class="finan-panel">
        <div class="finan-tit">
            <b>资质IBOSS生产系统数据统计</b>
        </div>
        <div class="panel-main">
                <table class="layui-table win60b" >
                    <thead>
                    <tr>
                        <th>事业部</th>
                        <th>待分配</th>
                        <th>待接收</th>
                        <th>办理中</th>
                        <th>生产暂停</th>
                        <th>待审核</th>
                        <th>退单驳回</th>
                        <th>已退单</th>
                        <th>生产完结</th>
                        <th>结项</th>
                        <th>中止</th>
                        <th>合计</th>
                    </tr>
                    </thead>
                    <tbody id="scOrderCount">
                    </tbody>
                </table>
        </div>
    </div>

    <div class="finan-panel">
        <div class="finan-tit">
            <b>资质IBOSS生产系统数据统计条形图</b>
        </div>
        <div id="container" style="width: 90%;height:400px;"></div>
    </div>
</div>
<%@ include file="../../footer.jsp" %>
<script type="text/javascript" src="${basePath}/static/js/zzsc/production/sc_common.js?v=${version}"></script>
<script src="${basePath}/static/js/zzsc/common/echarts.min.js?v=${version}"></script>

</body>
<script type="text/javascript">
    $(function () {
        syb("#signOrgId");
        // initData();
        loadScOrderAccount('#scOrderCount');
    });
    function checkHasSybAuth(obj) {
        var count = obj.length;
        if (checkIsEmpty(count) || count === 0) {
            return false;
        }
        return true;
    }
    /**
     * 加载统计数据信息
     */
    function loadScOrderAccount(obj, signOrgId) {
        var params = {};
        var checkResult = checkHasSybAuth($('#signOrgId option'));
        if (!checkResult) {
            params.isAll = "0";
        }else {
            params.isAll = "1";
        }
        if (!checkIsEmpty(signOrgId)) {
            params.signOrgId = signOrgId;
        }
        $.post(sysInfo.basePath + "/sc/all/sc_order_count_data.do", params, function (result) {
            if (result.code == 0) {
                $(obj).empty();
                var datas = result.data.orderCount;
                if (!checkIsEmpty(datas) && datas.length > 0) {
                    $.each(datas, function (i, item) {
                        $(obj).append("<tr>\n" +
                            "<td>" + item.productOrgName + "</td>\n" +
                            "<td>" + item.waitAllotCount + "</td>\n" +
                            "<td>" + item.waitReceiveCount + "</td>\n" +
                            "<td>" + item.inprocessCount + "</td>\n" +
                            "<td>" + item.suspendCount + "</td>\n" +
                            "<td>" + item.chargeBackingCount + "</td>\n" +
                            "<td>" + item.chargeBackBhCount + "</td>\n" +
                            "<td>" + item.chargeBackedCount + "</td>\n" +
                            "<td>" + item.orderOverCount + "</td>\n" +
                            "<td>" + item.orderJuncttonCount + "</td>\n" +
                            "<td>" + item.orderStopCount + "</td>\n" +
                            "<td>" + item.total + "</td>\n" +
                            "</tr>");
                    });
                } else {
                    $(obj).append("<tr>\n" +
                        "<td colspan='11'><center>没有数据</center></td>\n" +
                        "</tr></tbody>");
                }
                var orderTotal = result.data.orderTotal;
                if (checkIsEmpty(signOrgId) && !checkIsEmpty(orderTotal)) {
                        $(obj).append("<tr>\n" +
                            "<td style='color: red'>总计</td>\n" +
                            "<td style='color: red'>" + orderTotal.waitAllotTotal + "</td>\n" +
                            "<td style='color: red'>" + orderTotal.waitReceiveTotal + "</td>\n" +
                            "<td style='color: red'>" + orderTotal.inprocessTotal + "</td>\n" +
                            "<td style='color: red'>" + orderTotal.suspendTotal + "</td>\n" +
                            "<td style='color: red'>" + orderTotal.chargeBackingTotal + "</td>\n" +
                            "<td style='color: red'>" + orderTotal.chargeBackBhTotal + "</td>\n" +
                            "<td style='color: red'>" + orderTotal.chargeBackedTotal + "</td>\n" +
                            "<td style='color: red'>" + orderTotal.orderOverTotal + "</td>\n" +
                            "<td style='color: red'>" + orderTotal.orderJuncttonTotal + "</td>\n" +
                            "<td style='color: red'>" + orderTotal.orderStopTotal + "</td>\n" +
                            "<td style='color: red'>" + orderTotal.allTotal + "</td>\n" +
                            "</tr>");
                }
                //柱形图初始化
                chushihua(result);
            } else {
                DGG.Errors(result.msg);
                return false;
            }
        });
    }
    function refreshSata() {
        var signOrgId = $("#signOrgId").val();
        loadScOrderAccount('#scOrderCount', signOrgId);
    }

    //柱形图初始化
    function chushihua(result) {
        var orderCountList = result.data.orderCount;
        var nameData = [];//事业部名字
        var waitAllotCount = [];//待分配
        var waitReceiveCount = [];//待接收
        var inprocessCount = [];//办理中
        var suspendCount = [];//暂停
        var chargeBackingCount = [];//待审核
        var chargeBackBhCount = [];//退单驳回
        var chargeBackedCount = [];//已退单
        var orderOverCount = [];//已完结
        var orderJuncttonCount = [];//已结项
        var orderStopCount = [];//已终止
        for (var i = 0;i < orderCountList.length;i ++){
            nameData.push(orderCountList[i].productOrgName);
            waitAllotCount.push(orderCountList[i].waitAllotCount);
            waitReceiveCount.push(orderCountList[i].waitReceiveCount);
            inprocessCount.push(orderCountList[i].inprocessCount);
            suspendCount.push(orderCountList[i].suspendCount);
            chargeBackingCount.push(orderCountList[i].chargeBackingCount);
            chargeBackBhCount.push(orderCountList[i].chargeBackBhCount);
            chargeBackedCount.push(orderCountList[i].chargeBackedCount);
            orderOverCount.push(orderCountList[i].orderOverCount);
            orderJuncttonCount.push(orderCountList[i].orderJuncttonCount);
            orderStopCount.push(orderCountList[i].orderStopCount)
        }
        var dom = document.getElementById("container");
        var myChart = echarts.init(dom);
        var app = {};
        option = null;
        app.title = '统计条形图';

        option = {
            tooltip : {
                trigger: 'axis',
                axisPointer : {            // 坐标轴指示器，坐标轴触发有效
                    type : 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                }
            },
            legend: {
                data: ['待分配', '待接收','办理中','生产暂停','待审核','退单驳回','已退单','生产完结','结项','中止']
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '20%',
                containLabel: true
            },
            xAxis:  {
                type: 'value'
            },
            yAxis: {
                type: 'category',
                data: nameData
            },
            series: [
                {
                    name: '待分配',
                    type: 'bar',
                    stack: '总量',
                    label: {
                        normal: {
                            position: 'insideRight'
                        }
                    },
                    data: waitAllotCount
                },
                {
                    name: '待接收',
                    type: 'bar',
                    stack: '总量',
                    label: {
                        normal: {
                            position: 'insideRight'
                        }
                    },
                    data: waitReceiveCount
                },
                {
                    name: '办理中',
                    type: 'bar',
                    stack: '总量',
                    label: {
                        normal: {
                            position: 'insideRight'
                        }
                    },
                    data: inprocessCount
                },
                {
                    name: '生产暂停',
                    type: 'bar',
                    stack: '总量',
                    label: {
                        normal: {
                            position: 'insideRight'
                        }
                    },
                    data: suspendCount
                },
                {
                    name: '待审核',
                    type: 'bar',
                    stack: '总量',
                    label: {
                        normal: {
                            position: 'insideRight'
                        }
                    },
                    data: chargeBackingCount
                },
                {
                    name: '退单驳回',
                    type: 'bar',
                    stack: '总量',
                    label: {
                        normal: {
                            position: 'insideRight'
                        }
                    },
                    data:chargeBackBhCount
                },
                {
                    name: '已退单',
                    type: 'bar',
                    stack: '总量',
                    label: {
                        normal: {
                            position: 'insideRight'
                        }
                    },
                    data: chargeBackedCount
                },
                {
                    name: '生产完结',
                    type: 'bar',
                    stack: '总量',
                    label: {
                        normal: {
                            position: 'insideRight'
                        }
                    },
                    data: orderOverCount
                },
                {
                    name: '结项',
                    type: 'bar',
                    stack: '总量',
                    label: {
                        normal: {
                            position: 'insideRight'
                        }
                    },
                    data: orderJuncttonCount
                },
                {
                    name: '中止',
                    type: 'bar',
                    stack: '总量',
                    label: {
                        normal: {
                            position: 'insideRight'
                        }
                    },
                    data: orderStopCount
                }
            ]
        };
        if (option && typeof option === "object") {
            myChart.setOption(option, true);
        }
    }

    function exportOrderCount() {
        export_table('/sc/all/export_order_count_data.do', $("#scOrderFormCount").serializeObject());
    }
</script>
</html>
